package per.zqx.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import per.zqx.utils.RabbitUtils;

/**
 * TopicCustomer1
 *
 * @author Sa  2021-06-02 21:15
 */
public class TopicCustomer2 {
    static final String QUEUE_NAME = "topic_queue_2";
    static final String ROUTER_KEY = "#.log";
    @SneakyThrows
    public static void main(String[] args) {
        final Connection connection = RabbitUtils.getConnection();
        final Channel channel = connection.createChannel();
        channel.exchangeDeclare(TopicProducer.EXCHANGE_NAME, "topic");
        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        channel.queueBind(QUEUE_NAME, TopicProducer.EXCHANGE_NAME, ROUTER_KEY);
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            final String msg = new String(message.getBody(), "utf-8");
            System.out.println("TopicCustomer2 received a message -> " + msg);
        };
        boolean autoAck = true;
        channel.basicConsume(QUEUE_NAME, autoAck, deliverCallback, consumerTag -> {
        });
    }
}
